package com.pinyoumei.mq;

import java.util.Date;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pinyoumei.utils.DateUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/mq")
public class ProducerController {
	
	@Autowired
    private RabbitTemplate rabbitTemplate;
	
	@Value("${rabbitmq.email.exchange}")
	private String EXCHANGE_NAME;
	
	@Value("${rabbitmq.email.rout.key}")
	private String ROUTING_KEY;

	/**
	 * localhost:8888/mq/sendMessage
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/sendMessage")
	public String sendMsg(){
		String content = DateUtils.DateToString(new Date(), DateUtils.DATE_TO_STRING_DETAIAL_PATTERN);
		log.info("######EXCHANGE_NAME:"+EXCHANGE_NAME+",ROUTING_KEY:"+ROUTING_KEY+"#####");
		log.info("######生产者发送消息:"+content+"######");
		rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING_KEY, content);
	    return content;
	}
}
